<!--
 * @Author: your name
 * @Date: 2020-11-26 09:52:24
 * @LastEditTime: 2021-01-14 14:39:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solax-design\src\views\projectList\inverterData\inverterData.vue
-->
<template>
    <div class="inverterData-main-box">
        <div class="left-sub-box">
            <el-card class="box-card">
                <div slot="header" class="clearfix" >
                    <span @click="addInverterData">{{$t('inverter.info.add')}} <i class="el-icon-plus"></i></span>
                </div>
                <div>
                    <el-form ref="form" v-if='form.forms.length>0' :model="nowTableData" label-width="200px" label-position='left'>
                        <el-row :gutter="20">
                            <el-col :span="9" :offset="1">
                                <el-form-item :label="$t('project.data.inverter')" prop="inverterId" :rules="[{ required: true, message: $t('remind.not-null')}]"
                                              label-width="100px">
                                    <el-select v-model="nowTableData.inverterId" :placeholder="$t('common.msg.select.please')" filterable @change="inverterChange()">
                                        <el-option
                                                v-for="item in inverterList"
                                                :key="item.invID"
                                                :label="item.name"
                                                :value="item.invID + ''">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="9" :offset="1">
                                <el-form-item :label="$t('project.data.number-of-inverters')" prop="inverterNum" :rules="[{ required: true, message: $t('remind.not-null')}]"
                                              label-width="100px">
                                    <el-input style="width:85%;" v-model="nowTableData.inverterNum" :placeholder="$t('common.info.pl-insert-content')" @blur='inverterNumChange'></el-input>
                                    <i class="el-icon-tickets"
                                       style="font-size:20px;margin-left:15px;cursor:pointer;color: rgb(44, 154, 197);"
                                       @click="showDetailModal"></i>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div class="img-and-table-box" v-if='nowTableData.inverterId'>
                        <div class="img-box">
                            <img :src="imgUrlBase" alt="" width="100%" style="max-width:150px;" v-if='imgFlag'>
                        </div>
                        <div class="table-box" >
                            <el-table
                                :data="tableData"
                                max-height="250"
                                :border='false'
                                style="width: 100%"
                                align='center'
                                v-if='form.forms'
                            >   
                                <el-table-column type="index" :label="$t('new.PV.management.input')" align='center' :index='(index)=>{return (index+1)+"路"}'>
                                    <!-- <template slot-scope="scope">
                                        {{scope.row}}
                                    </template> -->
                                </el-table-column>
                                <el-table-column
                                    prop="id"
                                    :label="$t('new.PV.management.PV-array')"
                                >
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.pvArrayId" :placeholder="$t('common.msg.select.please')" @change='pvArrayChange(scope.row)'>
                                            <el-option
                                                    v-for="item in form.pvArrays"
                                                    :key="item.name"
                                                    :label="item.name"
                                                    :value="item.id">
                                            </el-option>
                                        </el-select> 
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="stringCount"
                                        :label="$t('new.PV.management.strings')"
                                >
                                    <template slot-scope="scope">
                                        <div style="padding:20px;">
                                            <el-input-number v-model="scope.row.stringCount" controls-position="right"
                                                            :min="1" @blur="countBlur(scope.row)" @change='tprojectSelectInverter({stringCount:scope.row.stringCount,invInputId:scope.row.index})' :disabled="scope.row.pvArrayId == 0 ? false:scope.row.pvArrayId?false:true"></el-input-number>
                                            <br>
                                            <span style='position:absolute;left:50%;transform: translateX(-50%);'>1...{{scope.row.stringCountMax}}</span>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="c"
                                        label=""
                                >
                                    <template slot-scope="scope">
                                        X
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="moduleCount"
                                        :label="$t('project.PV')"
                                >
                                    <template slot-scope="scope">
                                        <el-input-number v-model="scope.row.moduleCount" controls-position="right"
                                                         :min="1" @blur="modulCountBlur(scope.row)" @change='tprojectSelectInverter({moduleCount:scope.row.moduleCount,invInputId:scope.row.index})' :disabled="scope.row.pvArrayId == 0 ? false:scope.row.pvArrayId?false:true"></el-input-number>
                                        <br>
                                        <span style='position:absolute;left:50%;transform: translateX(-50%);'>{{scope.row.moduleCountMin}}...{{scope.row.moduleCountMax}}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <p style="text-align:center;color:#999;">{{$t('nominal.Power.Ratio.range')}}{{poFormData.nomPowerFrom}}% ~ {{poFormData.nomPowerTo}}%</p>
                        </div>
                    </div>
                </div>
            </el-card>
            <el-card class="margin-top20" style="width: 100%" v-if='form.forms.length>0' >
                <div slot="header" class="clearfix">
                    <span>{{$t('new.PV.management.overview-of-inverters')}}</span>
                </div>
                <div >
                    <el-table :data="form.forms" max-height="150" :border='false'  align='center' @row-click='tableClick' :row-class-name="tableRowClassName">
                        <el-table-column fixed prop="d" label=""  width="120">
                            <template slot-scope="scope">
                                <i v-if='scope.row.statusImg == 0' class="el-icon-success" style="color:green;font-size:16px;" ></i>
                                <i v-if='scope.row.statusImg == 1' class="el-icon-warning" style="color:orange;font-size:16px;" ></i>
                                <i v-if='scope.row.statusImg == 2' class="el-icon-warning" style="color:red;font-size:16px;" ></i>
                                {{scope.row.invName}}
                            </template>
                        </el-table-column>
                        <el-table-column   v-for="(pvArray,index) in form.pvArrays" :key='pvArray.usedModuleCount' width="150" v-if='pvArraysInvFlag'>
                            <template slot="header" slot-scope="scope">
                                {{pvArray.name}}
                                <br>
                                <span  class="green-color" v-if='parseInt(pvArray.usedModuleCount)<=parseInt(pvArray.moduleCount)'>{{pvArray.usedModuleCount + '/'+ pvArray.moduleCount}}</span>
                                <span  class="green-color" style="color:red;" v-else>{{pvArray.usedModuleCount + '/'+ pvArray.moduleCount}}</span>
                            </template>
                            <template slot-scope="scope">
                                <span v-if='item.pvArrayId == pvArray.id' v-for="(item,index1) in scope.row.inverterInputs"
                                      :key='index1'> 
                                    {{item.stringCount + '/' + item.moduleCount + '(' + parseInt(index1+1) + ')'}}<br></span>
                            </template>
                        </el-table-column>
                        <el-table-column  fixed="right" :label="$t('project.nominal-power-ratio')" min-width="150">
                            <template slot-scope="scope">
                                {{scope.row.nominalPowerRatio}}
                                <i v-if='parseInt(scope.row.nominalPowerRatio)>poFormData.nomPowerFrom && parseInt(scope.row.nominalPowerRatio)<poFormData.nomPowerTo' class="el-icon-success" style="color:green;font-size:16px;" ></i>
                                <el-tooltip v-if='parseInt(scope.row.nominalPowerRatio)<poFormData.nomPowerFrom' placement="top">
                                    <div slot="content">{{$t('nominal.Power.Ratio.smaller0')}}（< {{poFormData.nomPowerFrom}}%）。<br/>{{$t('nominal.Power.Ratio.smaller1')}}<br/>{{$t('nominal.Power.Ratio.smaller2')}}<br/>
                                   {{$t('nominal.Power.Ratio.smaller3')}}</div>
                                    <i class="el-icon-warning" style="color:orange;font-size:16px;" ></i>
                                </el-tooltip>
                                <el-tooltip v-if='parseInt(scope.row.nominalPowerRatio)>poFormData.nomPowerTo && parseInt(scope.row.nominalPowerRatio)<150' placement="top">
                                    <div slot="content">{{$t('nominal.Power.Ratio.smaller0.big')}}（> {{poFormData.nomPowerTo}}%）。<br/>{{$t('nominal.Power.Ratio.smaller1.big')}}<br/>{{$t('nominal.Power.Ratio.smaller2.big')}}<br/>
                                    {{$t('nominal.Power.Ratio.smaller3.big')}}</div>
                                    <i class="el-icon-warning" style="color:orange;font-size:16px;" ></i>
                                </el-tooltip>
                                <el-tooltip v-if='parseInt(scope.row.nominalPowerRatio)>150' placement="top">
                                    <div slot="content">{{$t('nominal.Power.Ratio.smaller0.big150.1')}}
                                        <br>
                                        {{$t('nominal.Power.Ratio.smaller0.big150.2')}}
                                    </div>
                                    <i class="el-icon-warning" style="color:red;font-size:16px;" ></i>
                                </el-tooltip>
                            </template>
                        </el-table-column>
                        <el-table-column fixed="right" :label="$t('project.data.PV-peak-power')" width="110">
                            <template slot-scope="scope">
                                {{scope.row.peakPower == undefined ? '':scope.row.peakPower + 'kwp'}}
                            </template>
                        </el-table-column>
                        <el-table-column fixed="right" prop="d" label="" width="50">
                            <template slot-scope="scope">
                                <a href="javascript:;" @click.stop='tprojectDeleteInverter(scope.row)'>
                                    <i class="el-icon-delete"></i>
                                </a>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-card>
            <el-card class="margin-top20" v-if='nowTableData.inverterId'>
                <div slot="header" class="clearfix">

                    <span v-if="nowTableData.resultInfoStatus == 4"><i  class="el-icon-success" style="color:green;font-size:16px;"   ></i>{{$t('new.PV.management.PV-array/Inverter.conditioned')}}</span>
                    <span v-else-if="nowTableData.resultInfoStatus == 5"><i  class="el-icon-success" style="color:green;font-size:16px;" ></i>{{$t('new.PV.management.PV-array/Inverter')}}</span>
                    <span v-else-if="nowTableData.resultInfoStatus == 3"><i  class="el-icon-warning" style="color:red;font-size:16px;" ></i>{{$t('user.inverter.dangerous')}}</span>
                    <span v-else-if="nowTableData.resultInfoStatus == 2"><i  class="el-icon-warning" style="color:red;font-size:16px;" ></i>{{$t('pv.array.dangerous')}}</span>
                    <span v-else-if="nowTableData.resultInfoStatus == 1"><i  class="el-icon-warning" style="color:orange;font-size:16px;" ></i>{{$t('user.capacity.loss')}}</span>
                    <span v-else> {{$t('new.PV.management.PV-array/Inverter.conditioned')}}</span>
                    
                </div>
                <div>
                    <el-table
                            :data="configTableData"
                            max-height="500"
                            :border='false'
                            align='center'
                            winth='100%'
                            stripe
                    >
                        <el-table-column
                                prop="d"
                                :label="$t('new.PV.management.configuration')"
                                fixed
                                width="200"
                        >
                            <template slot-scope="scope">
                                {{scope.row.text}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                prop="d"
                                label=""
                                fixed
                                width="150"
                        >
                            <template slot-scope="scope">
                                {{scope.row.value}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                prop="d"
                                label=""
                                fixed
                                width="180"
                        >
                            <template slot-scope="scope">
                                {{scope.row.text2}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                prop="d"
                                label=""
                                v-for='items in tableDataNoNull.length'
                                :key='items'
                                min-width="150"
                        >
                            <template slot="header" slot-scope="scope">
                                {{$t('new.PV.management.input')}} {{items}}
                            </template>
                            <template slot-scope="scope">
                                <!-- 光伏阵列-{{item}} -->
                                {{scope.row['value'+items]}}
                                
                                <span v-if='returnStatusFlag(scope.row)'>
                                    <i class="el-icon-success" style="color:green;font-size:16px;" v-if='!(returnStatus(scope.row["compatibilityParam"+items],scope.row.text2,"text").length>0)'></i>

                                    <el-tooltip placement="top" v-else-if='scope.row.text2 == $t("new.PV.management.Max.PV-voltage")'>
                                        <div slot="content" ><span v-for='(item,index) in returnStatus(scope.row["compatibilityParam"+items],scope.row.text2,"text")' :key='index'> {{item}} <br></span></div>
                                        <i class="el-icon-warning" style="color:red;font-size:16px;"></i>
                                    </el-tooltip>

                                    <!-- <el-tooltip placement="top" v-else-if='returnStatus(scope.row["compatibilityParam"+items],scope.row.text2,"text").length>0 && scope.row.text2 == $t("new.PV.management.peak-power-input") && scope.row["compatibilityParam"+items].maxPeakPowerStatus == 2'>
                                    </el-tooltip> -->
                                    
                                    <el-tooltip placement="top" v-else-if='returnStatus(scope.row["compatibilityParam"+items],scope.row.text2,"text").length>0&& !(scope.row.text2 == $t("new.PV.management.peak-power-input") && scope.row["compatibilityParam"+items].maxPeakPowerStatus == 2)'>
                                        <div slot="content" ><span v-for='(item,index) in returnStatus(scope.row["compatibilityParam"+items],scope.row.text2,"text")' :key='index'> {{item}} <br></span></div>
                                        <i class="el-icon-warning" :style='!(scope.row.text2 == $t("new.PV.management.peak-power-input") && scope.row["compatibilityParam"+items].maxPeakPowerStatus == 1)?"color:orange;font-size:16px;":"color:yellow;font-size:16px;"'></i>
                                    </el-tooltip>
                                </span>
                            <!-- <el-tooltip placement="top" >
                                <div slot="content">多行信息<br/>第二行信息</div>
                                <i class="el-icon-warning" style="color:red;font-size:16px;"></i>
                            </el-tooltip> -->
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-card>
        </div>
        <div class="right-sub-box">
            <rightReport :po-form-data="poFormData" :data-visible="dataVisible"></rightReport>
        </div>
        <inverterDetail :detailData='detailData'></inverterDetail>
    </div>
</template>

<script>
    import rightReport from '../rightReport'
    import inverterDetail from './inverterDetail'
    import baseTable from '../../../components/common/baseTable'
import { setTimeout } from 'timers';

    export default {
        components: {
            rightReport,
            inverterDetail,
            baseTable
        },
        props: {
            form: {
                type: Object,
                default:()=>{
                    return {}
                }
            },
            active:{
                type:Number,
                default:1,
            },
            poFormData: {}
        },
        data() {
            return {
                dataVisible: {
                    total: false,
                    performance: true,
                    overview: true
                },
                inverterList: [],
                firmName: [],
                configTableData: [{
                    text: this.$t('project.data.inverter')+'：',
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.PV-array')+'：',
                    value1: '光伏阵列-1',
                },{
                    text: this.$t('new.PV.management.independent-inputs'),
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.number-of-PV-modules'),
                    value1: '光伏阵列-1',
                },{
                    text: this.$t('new.PV.management.Max.DC-power'),
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.peak-power-input'),
                    value1: '光伏阵列-1',
                },{
                    text: this.$t('new.PV.management.Min.DC-voltage'),
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.typical-PV-voltage'),
                    value1: '光伏阵列-1',
                },{
                    text: this.$t('project.inv.u-inv-AC-from'),
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.Min.PV-voltage'),
                    value1: '光伏阵列-1',
                },{
                    text: this.$t('project.Max.DC-PV'),
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.Max.PV-voltage'),
                    value1: '光伏阵列-1',
                },{
                    text: this.$t('new.PV.management.Max.DC-current'),
                    value: 'SK-SU3000C',
                    text2: this.$t('new.PV.management.Max.current-of-PV-array'),
                    value1: '光伏阵列-1',
                }],
                tableData: [],
                tableDataNoNull: [],
                // column: [{
                //     title: '输入',
                //     value: 'a',
                // }, {
                //     title: '光伏阵列',
                //     value: 'b',
                // }, {
                //     title: '组串',
                //     value: 'c',
                // }, {
                //     title: '',
                //     value: 'c',
                // }, {
                //     title: '光伏模块',
                //     value: 'd',
                // },],
                firmName: [],
                rowIndex:0,
                nowTableData:{},
                flag:true,
                detailData:{},
                imgUrlBase:require('../../../assets/img/nbq.jpg'),
                imgFlag:true,
                pvArraysInvFlag:true

            };
        },
        computed: {
            returnTableWidth() {
                return `width: ${document.body.offsetWidth * 0.68}px;`
            },
            pvArraysInv(){
                return this.$store.state.sysStore.pvArraysInv
            },
            returnInverterNum(){
                return this.nowTableData.inverterNum
            },
            // poFormData(){
            //     return this.$store.state.sysStore.poFormData
            // }
        },
        watch: {
            returnInverterNum:{
                handler(nv,ov){
                    if(nv){
                        // this.save()
                        this.$emit('changeNext',true)
                    }
                }
            },
            pvArraysInv:{
                handler(nv,ov){
                    if(nv){
                        this.pvArraysInvFlag = false
                        let that = this
                        setTimeout(()=>{
                            that.pvArraysInvFlag = true
                        },100)
                        // this.form.pvArrays = nv
                        this.$set(this.form,'pvArrays',nv)
                    }
                }
            },
            active:{
                handler(nv,ov){
                    if(ov != 3 &&nv == 3){
                        console.log(nv,'activeI');
                        if(this.nowTableData.inverterNum){
                            this.tprojectSelectInverter({invCount:this.nowTableData.inverterNum})
                        }
                        this.save()
                    }
                }
            },
            imgUrlBase:{
                handler(nv,ov){
                    this.imgFlag = false
                    let that = this
                    setTimeout(()=>{
                        that.imgFlag = true
                    },500)
                    
                },
                deep:true,
                immediate:true
            },
            tableData:{
                handler(nv,ov){
                    if(nv){
                        let arr = []
                        let i=0
                        nv.forEach(item => {
                            if(item){
                                item['index']=i
                                arr.push(item)
                                i++
                            }
                        });
                        // this.tableData = arr
                        this.tableDataNoNull = arr
                        this.setLastTableData()
                    }
                },
                deep:true
            },
            form:{
                handler(nv,ov){
                    console.log('nv-inverter');
                },
                deep:true,
                immediate:true
            },
            nowTableData:{
                handler(nv,ov){
                    this.$store.commit('setInvFormData',nv)
                    if(nv){
                        // if(nv.inverterId != ov.inverterId){
                            this.returnImgUrl()
                        // }
                    }
                },
                deep:true
            }
        },
        created() {

        },
        mounted() {
            this.getInverterListData()
        },
        methods: {
            returnStatusFlag(row){
                let flag  = true
                if(row.text == this.$t('project.data.inverter')+'：' || row.text == this.$t('new.PV.management.independent-inputs') || row.text == this.$t('new.PV.management.Max.DC-power')+'(cosφ=1)：'){
                    flag  = false
                }
                return flag
            },
            pvArrayChange(row){
                let obj={
                    pvArrayId:row.pvArrayId,
                    invInputId:row.index,
                    stringCount:row.stringCount || 1,
                    moduleCount:row.moduleCount || 1,

                }
                this.tprojectSelectInverter(obj)
            },
            async returnImgUrl(){
                if(this.nowTableData.pictureUrl){
                    let res= await this.API.systemTuserGetLogo({
                        fileName:this.nowTableData.pictureUrl
                    })
                    if(res){
                        this.imgUrlBase ='data:image/gif;base64,' + res
                    }else{
                        this.imgUrlBase = require('../../../assets/img/nbq.jpg')
                    }
                }else{
                    this.imgUrlBase = require('../../../assets/img/nbq.jpg')
                }
            },
            async tprojectSelectInverter(obj){
                let arr = Object.keys(obj)
                for(let i = 0;i<arr.length;i++){
                    if((!obj[arr[i]])& obj[arr[i]] !=0){
                        return
                    }
                }
                let res = await this.API.tprojectSelectInverter(Object.assign({},{
                    projectId:this.$route.query.id,
                    invSequence:this.nowTableData.invSequence,
                    inverterId:this.nowTableData.inverterId
                },obj))
                if(res&&res.code&&res.code ==500){
                    return
                }

                this.$emit('noticeUpload',res)
                // this.form.pvArrays = res.pvArrays
                this.$set(this.form,'pvArrays',res.pvArrays)
                this.assembleInverterData(res)
                
            },
            modulCountBlur(row){
                if(!row.moduleCount){
                    row.moduleCount = 1
                }
            },
            countBlur(row){
                if(!row.stringCount){
                    row.stringCount = 1
                }
            },
            assembleInverterData(obj){
                let arr = [];
                Object.keys(obj.iorMap).forEach(item=>{
                    obj.iorMap[item]['invSequence'] = item
                    arr.push(obj.iorMap[item])
                })
                
                this.$set(this.form.forms,this.nowTableData.invSequence-1,arr[this.nowTableData.invSequence-1])
                this.tableData = arr[this.nowTableData.invSequence-1].inverterInputs
                this.nowTableData = arr[this.nowTableData.invSequence-1]
                let i = 0
                obj.pvArrays.forEach(item=>{
                    if(item){
                        item['id'] = i
                        this.$set(this.form.pvArrays,i,item)
                    }
                    i++
                })
            },
            tableRowClassName({row, rowIndex}) {
                row['index'] = rowIndex
                if(this.flag){
                    this.tableData = row.inverterInputs
                    this.nowTableData = row
                    this.flag = false
                    // setTimeout(()=>{
                        
                    // },100)
                }
                if (rowIndex === this.rowIndex) {
                return 'success-row';
                } 
                return '';
            },
            //组装兼容数据
            async setLastTableData(){
                let res = await this.API.tinverterGetByInverterId({
                    inverterId:this.nowTableData.inverterId
                })
                let arr = []
                if(res.inputCount>0){
                    for(let i = 0;i<res.inputCount;i++){
                        arr.push(res[`iInvDCMax${i+1}`]||'-')
                    }
                }

                this.configTableData[0].value = res.name
                this.configTableData[1].value = res.inputCount
                this.configTableData[2].value = (res.pInvDCmax?res.pInvDCmax/1000:'-') + 'kW'
                this.configTableData[3].value = res.uInvPVmin + 'V'
                this.configTableData[4].value = res.uInvACFrom + 'V / '+res.uInvACTo + 'V'
                this.configTableData[5].value = res.uInvDCmax + 'V'
                this.configTableData[6].value = arr.join('/') + 'A'
                for(let i = 0;i<this.tableDataNoNull.length;i++){
                    // this.configTableData[0][`value${i+1}`] ='光伏阵列-'+ (i+1)
                    this.$set(this.configTableData[0],`value${i+1}`,this.returnModalName(this.tableDataNoNull[i].pvArrayId))
                    this.$set(this.configTableData[1],`value${i+1}`,this.tableDataNoNull[i].moduleCount)
                    this.$set(this.configTableData[2],`value${i+1}`,this.tableDataNoNull[i].peakPower/1000+'kWp')
                    this.$set(this.configTableData[3],`value${i+1}`,this.tableDataNoNull[i].uTypicalPV + 'V')
                    this.$set(this.configTableData[4],`value${i+1}`,this.tableDataNoNull[i].uMinPV + 'V')
                    this.$set(this.configTableData[5],`value${i+1}`,this.tableDataNoNull[i].uMaxPV + 'V')
                    this.$set(this.configTableData[6],`value${i+1}`,this.tableDataNoNull[i].iMaxPVArray + 'A')

                    this.$set(this.configTableData[0],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                    this.$set(this.configTableData[1],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                    this.$set(this.configTableData[2],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                    this.$set(this.configTableData[3],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                    this.$set(this.configTableData[4],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                    this.$set(this.configTableData[5],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                    this.$set(this.configTableData[6],`compatibilityParam${i+1}`,this.tableDataNoNull[i].compatibilityParam)
                }
                
            },
            /*逆变器修改*/
            inverterChange() {
                let obj = {
                    
                }
                this.save()
                this.tprojectSelectInverter({inverterId:this.nowTableData.inverterId})
            },
            returnStatus(obj,item,type){
                let arr = []
                if(obj){
                    let statusName ={}
                    statusName[this.$t('new.PV.management.typical-PV-voltage')]={
                                0:[],
                                1:[this.$t('user.capacity.loss'),this.$t('new.PV.management.2sb-1300tl'),this.$t('max.pv.array.solution.voltage.smaller')]
                            }
                    statusName[this.$t('new.PV.management.Min.PV-voltage')]={
                                0:[],
                                1:[this.$t('user.capacity.loss'),this.$t('new.PV.management.2sb-1300tl'),this.$t('max.pv.array.solution.current.bigger')]
                            }

                    statusName[this.$t('new.PV.management.Max.PV-voltage')]={
                                0:[],
                                1:[this.$t('pv.array.dangerous'),this.$t('max.voltage.bigger.than.pv.array'),this.$t('max.voltage.solution.bigger.than.pv.array')],
                                2:[this.$t('user.inverter.dangerous'),this.$t('max.voltage.bigger.than.inverter'),this.$t('nominal.Power.Ratio.normal')]
                            },
                            
                    statusName[this.$t('new.PV.management.Max.current-of-PV-array')]={
                                0:[],
                                1:[this.$t('user.capacity.loss'),this.$t('max.pv.array.current.bigger'),this.$t('max.pv.array.solution.current.bigger')]
                            }
                    statusName[this.$t('new.PV.management.peak-power-input')]={
                                0:[],
                                1:[this.$t('user.capacity.loss'),this.$t('max.pv.array.current.bigger.2'),this.$t('max.pv.array.current.bigger.3')],
                                2:[1]
                            }
                    if(item == this.$t('new.PV.management.typical-PV-voltage')){
                        arr = statusName[this.$t('new.PV.management.typical-PV-voltage')][obj.normalVoltageStatus]
                    }
                else if(item == this.$t('new.PV.management.Min.PV-voltage')){
                        arr = statusName[this.$t('new.PV.management.Min.PV-voltage')][obj.minVoltageStatus]
                    }
                else if(item == this.$t('new.PV.management.Max.PV-voltage')){
                        arr = statusName[this.$t('new.PV.management.Max.PV-voltage')][obj.maxVoltageStatus]
                    }
                else if(item == this.$t('new.PV.management.Max.current-of-PV-array')){
                        arr = statusName[this.$t('new.PV.management.Max.current-of-PV-array')][obj.maxPVCurrentStatus]
                    }
                else if(item == this.$t('new.PV.management.peak-power-input')){
                        arr = statusName[this.$t('new.PV.management.peak-power-input')][obj.maxPeakPowerStatus]
                    }
                    else{
                        arr = []
                    }
                }
                return arr
            },
            returnModalName(id){
                let name = ''
                this.form.pvArrays.forEach(item =>{
                    if(item.id == id){
                        name = item.name
                    }
                })
                return name
            },

            /*获取逆变器数据*/
            async getInverterListData() {
                let res = await this.API.systemTinverterGetList({})
                this.inverterList = res
            },
            async tprojectDeleteInverter(row){
                let res = await this.API.tprojectDeleteInverter({
                    invSequence:row.invSequence,
                    projectId:this.$route.query.id,
                })
                this.$emit('noticeUpload',res)
                this.rowIndex = 0
                this.tableData = this.form.forms[0].inverterInputs
            },
            addInverterData() {
                if(this.form.forms.length == 0){
                    this.form.forms.push({invSequence:1})
                }else{
                    this.form.forms.push({})
                }
                // this.form.forms.push({})
                this.rowIndex = this.form.forms.length-1
                let index = this.form.forms[this.form.forms.length-2].invSequence || 0

                this.nowTableData = {invSequence:parseInt(index)+1}
            },
            tableClick(row, column, event) {
                if(!this.nowTableData.inverterId){
                    this.form.forms.pop()
                }
                this.rowIndex = row.index
                this.tableData = row.inverterInputs
                // let newRow = JSON.parse(JSON.stringify(row))
                this.$set(this._data,'nowTableData',row)
            },
            async showDetailModal(){
                this.$store.commit('setVisibleInfo',true)
                let res = await this.API.tinverterGetByInverterId({
                    inverterId:this.nowTableData.inverterId
                })
                this.detailData = res
            },
            inverterNumChange(){
                this.save()
                this.tprojectSelectInverter({invCount:nowTableData.inverterNum})
            },
            save(){
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                        // this.$emit('noticeUpload',true)
                        // this.$emit('closeAll',true)
                        this.$emit('changeNext',true)
                    } else {
                        this.$emit('closeAll',false)
                        return false;
                    }
                });
            }
        },
    };
</script>

<style lang="less">
    .inverterData-main-box {
        display: flex;

        .el-card__header {
            background-color: #ddd;
            cursor: pointer;
        }

        .left-sub-box {
            flex: 9;
            width: 75%;
            padding: 10px;

            .box-card {
                .el-card__header:hover {
                    color: rgb(44, 154, 197);
                }
            }

            // .el-table__body tbody tr:nth-child(2n+1){
            //     background-color: #eee;
            // }
        }

        .right-sub-box {
            flex: 3;
            width: 25%;
            padding: 10px;
        }

        .img-and-table-box {
            display: flex;

            .img-box {
                flex: 1;
                width: 20%;
            }

            .table-box {
                flex: 7;
                width: 20%;
            }
        }

        .el-table::before {
            background-color: #fff;
        }

        .el-table td {
            border-bottom: none;
            text-align: center;
        }

        .el-table th.is-leaf {
            border-bottom: none;
            text-align: center;
        }

        .margin-top20 {
            margin-top: 20px;
        }

        .green-color {
            color: green;
        }

        .red-color {
            color: red;
        }
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: rgb(255, 219, 168);
        }
    }
</style>
